
/* GCSx
** IMGCHOOSE.H
**
** Image "chooser" popup window or control
*/

/*****************************************************************************
** Copyright (C) 2003-2006 Janson
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
** 
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
*****************************************************************************/

#ifndef __GCSx_IMGCHOOSE_H_
#define __GCSx_IMGCHOOSE_H_

class ImageChooser : public Window {
private:
    class TileSetEdit* tileset;
    class FrameWindow* myFrame;
    class WidgetScroll* myScroll;
    
    int numTiles; // We keep this at -1 to make our calculations easier
    int tileWidth;
    int tileHeight;
    int tilesPerLine;
    int fixedTilesPerLine;
    
    int cursor; // We keep this at -1 to make our calculations easier
    int haveFocus;
    
    // Dirty range
    Rect dirtyRange;

    // Set partial dirties
    void setDirtyRange(int first, int last);
    void setDirtyBox(int begin, int end);

public:
    // (NULL tileset ok)
    // Locks tileset until deleted or changed
    ImageChooser(class TileSetEdit* myTileset);
    ~ImageChooser();
    
    // Can change tileset later
    void setTileset(class TileSetEdit* newTileset);

    // Opens the window, returns selected tile (1+)
    // x/y is requested position of the lower left corner
    int runModal(int xPos, int yPos);
    
    // Adds self to dialog using a WScroll
    void addTo(class Dialog* dialog, int showWidth, int showHeight, int cId);
    
    void reloadTileStats();
    int cursorState(int newPos = -1);

    int event(int hasFocus, const SDL_Event* event);
    void resize(int newWidth, int newHeight, int newViewWidth = -1, int newViewHeight = -1, int fromParent = 0);
    void display(SDL_Surface* destSurface, Rect& toDisplay, const Rect& clipArea, int xOffset, int yOffset);
    WindowType windowType() const;
    WindowSort windowSort() const;
    
    // Not auto-deleted if a standalone modal window
    // Auto-deleted if a widget
    int wantsToBeDeleted() const;
};

#endif

